package 力扣.数组;

public class 删除排序数组中的重复项26 {
    public static void main(String[] args) {
//        int[] ints = new int[]{0,0,1,1,1,2,2,2,3,3,4};
//        int[] ints = new int[]{1,1,1,1,1,1};
        int[] ints = new int[]{1,1,2};
        int i = removeDuplicates(ints);
        for (int j = 0; j < i ; j++) {
            System.out.print(ints[j]+" ");
        }

    }

    /**
     * 快慢指针法
     * @param nums
     * @return
     */
    public static int removeDuplicates(int[] nums) {
        int flag = 0;//flag为慢指针
        for (int i = 1; i < nums.length; i++) {// i为快指针
               if (nums[i] != nums[i-1]){
                   flag++;
                   nums[flag] = nums[i];
               }
        }
        return flag+1;//返回长度
    }
}
